package com.codedancer.campus.mapper;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.po.Carousel;
import com.codedancer.campus.qo.carousel.CarouselPageSearchQo;
import java.util.List;

public interface CarouselMapper extends BaseMapper<Carousel> {

    /**
     * 分页查询轮播图
     *
     * @param carouselPage
     * @param carouselPageSearchQo
     * @return
     */
    default IPage<Carousel> page(Page<Carousel> carouselPage,
        CarouselPageSearchQo carouselPageSearchQo) {
        LambdaQueryWrapper<Carousel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtil.isNotEmpty(carouselPageSearchQo.getName())) {
            lambdaQueryWrapper.like(Carousel::getName, carouselPageSearchQo.getName());
        }
        if (ObjectUtil.isNotEmpty(carouselPageSearchQo.getDescription())) {
            lambdaQueryWrapper.like(Carousel::getDescription,
                carouselPageSearchQo.getDescription());
        }
        lambdaQueryWrapper.orderByAsc(Carousel::getDisabled);
        return selectPage(carouselPage, lambdaQueryWrapper);
    }

    /**
     * 查询全部启用的轮播图
     *
     * @return
     */
    default List<Carousel> listAllEnable() {
        LambdaQueryWrapper<Carousel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Carousel::getDisabled, false);
        lambdaQueryWrapper.orderByDesc(Carousel::getCreateTime);
        return selectList(lambdaQueryWrapper);
    }
}
